package com.wlyuan.open.scanner.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.dto.OpenPaySyncDTO;
import com.wlyuan.open.dto.finance.BillTransportDTO;
import com.wlyuan.open.scanner.domain.finance.pay.BillPay;
import com.wlyuan.open.scanner.domain.transport.Transport;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ScannerPayAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {MappingInvalid.class, MappingIds.class})
    public interface Assembler {

        /**
         * 转换
         *
         * @param source
         * @return
         */
        @Mappings({
                @Mapping(source = "createTime", target = "createAt"),
                @Mapping(source = "updateTime", target = "updateAt"),
        })
        OpenPaySyncDTO assemble(BillPay source);

        @Mappings({
                @Mapping(source = "id", target = "transportId"),
                @Mapping(source = "info.totalAmount", target = "info.totalQuantity"),
                @Mapping(source = "info.echo", target = "echo"),
                @Mapping(source = "createTime", target = "info.createAt"),
                @Mapping(source = "carrier", target = "upStream"),
                @Mapping(source = "customer", target = "downStream"),
        })
        BillTransportDTO assemble(Transport source);

        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<OpenPaySyncDTO> assemble(List<BillPay> source);

    }

    public static List<OpenPaySyncDTO> assemble(List<BillPay> creation) {
        return ASSEMBLER.assemble(creation);
    }

    public static OpenPaySyncDTO assemble(BillPay creation) {
        return ASSEMBLER.assemble(creation);
    }

}
